package org.ezplatform.office.forum.dao;

import java.util.List;
import java.util.Map;

import org.ezplatform.core.dao.jpa.JpaBaseDao;
import org.ezplatform.office.forum.entity.ForumPost;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

/**
 *  论坛dao
 * 2019年11月2日17:40:59
 * @author Administrator
 *
 */
@Repository
public interface ForumPostDao extends JpaBaseDao<ForumPost, String> {
	
	//删除方法
	@Modifying
	@Query(nativeQuery = true, value = "delete from oa_forum_post where id=?1")
	public abstract int deleteRepost(String id);
	
	//删除方法
	@Modifying
	@Query(nativeQuery = true, value = "delete from oa_forum_post where id=?1 or post_id=?1 ")
	public abstract int deleteMainpost(String id);
	
	@Query(" from ForumPost where boardId in (?1) and isDelete = ?2 and type = '1' ")
	List<ForumPost> getPostByBoard(List<String> list,int isDelete);
	
	@Query(" from ForumPost where author = ?1 and id =?2 and isDelete = 0  ")
	ForumPost getPostByAuthor(String author,String id);
	
	@Query(" from ForumPost where isDelete = 0 and corpId = ?1 ")
	List<ForumPost> getPostInfo(String corpId);
	
	@Query("from ForumPost where id in (?1) and checkStatus =?2 and isDelete = 0 ")
	List<ForumPost> getCheckByIdAnDStatus(List<String> id,String checkStatus);
	
	@Query("from ForumPost where id in (?1)  and isDelete = 0 ")
	List<ForumPost> getMoveByIds(List<String> id);
	
	@Modifying
	@Query(nativeQuery = true, value = "update oa_forum_post set is_read = 0 where id = ?1")
	int markRead(String postId);
	
	/**
	 * 获取当前帖子上级评论
	 * @param postId
	 * @return
	 */
	@Query(" from ForumPost where id = ?1 ")
	List<ForumPost> getUpContent(String postId);
	
	/**
	 * 通过id,获取主贴下回帖/回帖下评论的数量
	 * @param string
	 * @return
	 */
	@Query("from ForumPost where postId  =?1  and isDelete = 0 and type = 3")
	List<ForumPost> getPostCount(String id);
	
	@Query("from ForumPost where postId  =?1  and isDelete = 0")
	List<ForumPost> getMoveSonByIds(String id);
	
	@Query("from ForumPost where author =?1 and corpId = ?2 and type = ?3 and isDelete = 0 and checkStatus in (?4) ")
	List<ForumPost>  getPostCountByAuthorAndType(String userId, String corpId, int type, List<String> status);
	
}
